<?php
	require("../function.php");
	$con = getconnect("china");
	$email=$_POST['email'];
	$usern =$_POST['username'];
	$passw =md5($_POST['password1']);
	$yzm= $_POST['img_code'];
	$passw2 =md5($_POST['password2']);
	$emailcode=$_POST['mail_code'];
	if($usern==""){
		skip("用户名不能为空","../../register.html");
	}
	elseif($_POST['password1']==""){
		skip("密码不能为空","../../register.html");
	}
	elseif($_POST['password2']==""){
		skip("请确认密码","../../register.html");
		die();
	}
	elseif(strcmp(strtolower($yzm),strtolower($_SESSION['code']))!=0)
	{
		skip("验证码错误!","../../register.html");
		die();
	}
	elseif($_POST['email']=="")
	{
		skip("邮箱不能为空!","../../register.html");
		die();
	}
	elseif($_SESSION['emailcode']!=$emailcode){
		skip("邮箱验证码错误!","../../register.html");
		die();
	}		
	else 
	{	
		$sql4 = "SELECT * FROM users where username=".$usern." and state=1 ;";
		$result = mysqli_query($con,$sql4);
		if(mysqli_num_rows($result)>0)
		{
			skip("账号已被注册，换一个试试!","../../register.html");
		}
		$_SESSION['user']=$usern;
		$sql3 = "insert users (email,username,password)values('$email','$usern','$passw');";
		mysqli_query($con,$sql3);
		skip("Registered successful!","../../index.html");
	}

?>



